#include "ws2812b.h"

#include "FreeRTOS.h"
#include "task.h"

void WS2812B_Init(){

	GPIO_InitTypeDef  GPIO_InitStructure;

	  RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOD , ENABLE );
	  /* Configure the GPIO_LED pin */
	  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	  GPIO_Init(GPIOD, &GPIO_InitStructure);

	  vTaskDelay(2000/portTICK_RATE_MS);


	  uint8_t red =0;
		  uint8_t green =0;
		  uint8_t blue =0;
		  int i=0;

	while(1){

switch(i){
		case 0:
			red = 0;
			green = 0;
			blue = 0;
			i++;
			break;

		case 1:
			red = 255;
			green = 0;
			blue = 0;
			i++;
			break;
		case 2:
			red = 255;
			green = 255;
			blue = 0;
			i++;
			break;
		case 3:
			red = 0;
			green = 255;
			blue = 0;
			i++;
			break;
		case 4:
			red = 0;
			green = 255;
			blue = 255;
			i++;
			break;
		case 5:
			red = 0;
			green = 0;
			blue = 255;
			i++;
			break;
		case 6:
				red = 255;
				green = 0;
				blue = 255;
				i++;
				break;
		case 7:
				red = 255;
				green = 255;
				blue = 254;
				i++;
				break;
		default :
			i=0;
			break;
}




/*
	//bit 0
		//0,5us
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		//8,5us
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET


	//bit1
		//0,85us
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET
		GPIOD->BSRR = GPIO_Pin_9; //SET

		//0,5us
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		GPIOD->BRR = GPIO_Pin_9;//RESET
		**/




/*

		for (i=0;i<8;i++){
			//bit 0
				//0,5us
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				//GPIOD->BSRR = GPIO_Pin_9; //SET
				//8,5us
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
		}

		for (i=0;i<8;i++){
			//bit1
				//8,5us
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET

				//0,5us
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				//GPIOD->BSRR = GPIO_Pin_9; //SET
		}

		for (i=0;i<8;i++){
			//bit1
				//8,5us
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET
				GPIOD->BRR = GPIO_Pin_9;//RESET

				//0,5us
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				GPIOD->BSRR = GPIO_Pin_9; //SET
				//GPIOD->BSRR = GPIO_Pin_9; //SET
		}
*/

	/*	for (i=0;i<8;i++){

			if(green & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			green*=2;
		}



		for (i=0;i<8;i++){

			if(red & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			red*=2;
		}


		for (i=0;i<8;i++){

			if(blue & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			blue*=2;
		}
*/


		  GPIOD->BRR = GPIO_Pin_9;//RESET
vTaskDelay(1/portTICK_RATE_MS);
//GPIOD->BSRR = GPIO_Pin_9; //SET



			if(green & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b01000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00100000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00010000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00001000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00000100){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00000010){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(green & 0b00000001){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}

						if(red & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b01000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00100000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00010000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00001000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00000100){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00000010){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(red & 0b00000001){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}

						if(blue & 0b10000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b01000000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00100000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00010000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00001000){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00000100){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00000010){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}
			if(blue & 0b00000001){
				//bit1
					//0,85us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET

					//0,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
			}
			else{
				//bit 0
					//0,5us
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					GPIOD->BSRR = GPIO_Pin_9; //SET
					//GPIOD->BSRR = GPIO_Pin_9; //SET
					//8,5us
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESET
					//GPIOD->BRR = GPIO_Pin_9;//RESE
			}





			GPIOD->BSRR = GPIO_Pin_9; //SET
		vTaskDelay(100/portTICK_RATE_MS);




	}
}
